// pages/book/book.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    book:[],
    chapters: [],
    id:'',
    sourceId:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    var that = this 
    that.setData({
      id: options.id,

    })
        /* 获取小说源ID*/
    wx.request({
      url: 'https://api.zhuishushenqi.com/atoc?view=summary&book=' + options.id, //小说源ID
      method: 'GET',
      data: {},
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {

        console.log('@1',res);

        that.setData({
          sourceId: res.data[0]['_id'],
        })
      }
      

    }),
      that.getSource()
    /* 获取小说名字*/
    wx.request({
      url: 'https://api.zhuishushenqi.com/book/' + options.id, //bookID
      method: 'GET',
      data: {},
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        that.setData({
          book: res.data,

        })
        wx.setNavigationBarTitle({
          title: res.data.title
        })
        console.log(that.book)
      },

    }),
      
    
    that.getSource()
  },
  getSource: function (sourceId){
    var that = this
    console.log('#1', that.data.sourceId);
  wx.request({
    url: 'https://api.zhuishushenqi.com/atoc/5817f1137063737f47bb47fd?view=chapters', //小说源ID
    method: 'GET',
    data: {
    },
    header: {
      'content-type': 'application/json'
    },
    success: function (res) {
      console.log(that.data.sourceId)
      console.log(res);
      that.setData({
        source: res.data.chapters.slice(0, 5),
      })


    },

  })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})